#*********************************************************************************
# ** 文件名称：gdm_ord_order.sh
# ** 功能描述：订单模型表
# ** 创建者：xiaoxu
# ** 修改日期：19-06-13
# ** 修改人：
# ** 修改内容：
#*********************************************************************************
#!/usr/bin/env bash

DT = ` date -d '-1 day' "+%y-%m-%d" `
sysdate =  ` date  "+%y-%m-%d" `

#如果有参数传入，重跑脚本时使用（06-13号跑06-09的任务时）
if [$1]; then
  DT = $1
fi

SQL = "
    insert overwrite table gdm_ord_order partition(dt=' "${DT}" ')
    select a.order_id, -- 订单id
           a.order_no,
           a.order_date,
           a.user_id,
           a.user_name,
           a.shop_id,
           a.shop_name,
           a.brand_id,
           a.brand_name,
           a.order_money,
           a.order_type,
           a.order_status,
           a.pay_type,
           a.order_status,
           a.order_source,
           b.consignee,
           b.area_id,
           b.area_name,
           b.address,
           b.mobilephone,
           b.telphone,
           b.coupon_id,
           b.coupon_money,
           b.carriage_money,
           a.create_time,
           a.last_update_time,
           from_unixtime(unix_timestamp()) dw_date
       from (select * from fdm.fdm_ord_order where dt = ' "${DT}" ') a
       join (select * from fdm.fdm_ord_order_desc where dt = ' "${DT}" ') b
         on (a.order_id = b.order_id);
"

#打印SQL语句
echo "${SQL}"

hive -e "${SQL}"